package tab

import (
	"code.google.com/awwwe-browser/data"
)

var BrowserTabs SliceTab

func init() {
	BrowserTabs = BuildSliceTab(0, 20)
}

// a tab slice
type SliceTab struct {
	data.SlicerBase
}

// a cmp method for feeds
func cmpTab(i1 interface{}, i2 interface{}) int {
	if i1.(*Tab).Key == i2.(*Tab).Key {
		return 0
	} else if i1.(*Tab).Key > i2.(*Tab).Key {
        return 1
    }
    return -1
}

// BuildSliceTab constructs a tab slice.
func BuildSliceTab(length, capacity int) SliceTab {
	var v SliceTab
	v.Init(length, capacity, cmpTab)
	return v
}

// AtIndex returns the slice's element at the slice's index.
// Param index is the index of the slice.
func (this *SliceTab) AtIndex(index int) *Tab {
	var ifc interface{}
    ifc = this.SlicerBase.AtIndex(index)
    if ifc != nil {
        return ifc.(*Tab)
    } else {
        return nil
    }
}

// Returns the data as a slice.
func (this *SliceTab) Slice() []*Tab {
	var i, length int
	var item interface{}
	var ss []*Tab
	length = len(this.Data)
	ss = make([]*Tab, length, length)
	for i, item = range this.Data {
		ss[i] = item.(*Tab)
	}
	return ss
}

// Remove gets an item at index
// Deletes the item at index form the array
// Returns the item.
func (this *SliceTab) Remove(index int) *Tab {
	var ifc interface{}
	ifc = this.SlicerBase.Remove(index)
    if ifc != nil {
		return ifc.(*Tab)
    }
    return nil
}

// AppendSlice appends a slice of feeds to the slice.
func (this *SliceTab) AppendSlice(src []Tab) {
	var v Tab
    for _, v = range src {
    	this.Append(v)
    }
}

// ReplaceAt replaces an element in the slice.
func (this *SliceTab) ReplaceAt(at int, src *Tab) bool {
	var length int
    length = len(this.Data)
    if at >= 0 && at < length {
    	this.Data[at] = src
        return true
    } else if at >= length {
        this.Append(src)
        return true
    }
    return false
}

